{"ast":null,"code":"import _slicedToArray from \"/Users/poppie/Desktop/development/messenger/app/frontend/node_modules/@babel/runtime/helpers/esm/slicedToArray.js\";\nimport _toConsumableArray from \"@babel/runtime/helpers/esm/toConsumableArray\";\nimport * as React from 'react';\nimport usePatchElement from '../../_util/hooks/usePatchElement';\nimport { withConfirm, withError, withInfo, withSuccess, withWarn } from '../confirm';\nimport HookModal from './HookModal';\nvar uuid = 0;\nvar ElementsHolder = /*#__PURE__*/React.memo( /*#__PURE__*/React.forwardRef(function (_props, ref) {\n  var _usePatchElement = usePatchElement(),\n    _usePatchElement2 = _slicedToArray(_usePatchElement, 2),\n    elements = _usePatchElement2[0],\n    patchElement = _usePatchElement2[1];\n  React.useImperativeHandle(ref, function () {\n    return {\n      patchElement: patchElement\n    };\n  }, []);\n  // eslint-disable-next-line react/jsx-no-useless-fragment\n  return /*#__PURE__*/React.createElement(React.Fragment, null, elements);\n}));\nfunction useModal() {\n  var holderRef = React.useRef(null);\n  // ========================== Effect ==========================\n  var _React$useState = React.useState([]),\n    _React$useState2 = _slicedToArray(_React$useState, 2),\n    actionQueue = _React$useState2[0],\n    setActionQueue = _React$useState2[1];\n  React.useEffect(function () {\n    if (actionQueue.length) {\n      var cloneQueue = _toConsumableArray(actionQueue);\n      cloneQueue.forEach(function (action) {\n        action();\n      });\n      setActionQueue([]);\n    }\n  }, [actionQueue]);\n  // =========================== Hook ===========================\n  var getConfirmFunc = React.useCallback(function (withFunc) {\n    return function hookConfirm(config) {\n      var _a;\n      uuid += 1;\n      var modalRef = /*#__PURE__*/React.createRef();\n      var closeFunc;\n      var modal = /*#__PURE__*/React.createElement(HookModal, {\n        key: \"modal-\".concat(uuid),\n        config: withFunc(config),\n        ref: modalRef,\n        afterClose: function afterClose() {\n          closeFunc === null || closeFunc === void 0 ? void 0 : closeFunc();\n        }\n      });\n      closeFunc = (_a = holderRef.current) === null || _a === void 0 ? void 0 : _a.patchElement(modal);\n      return {\n        destroy: function destroy() {\n          function destroyAction() {\n            var _a;\n            (_a = modalRef.current) === null || _a === void 0 ? void 0 : _a.destroy();\n          }\n          if (modalRef.current) {\n            destroyAction();\n          } else {\n            setActionQueue(function (prev) {\n              return [].concat(_toConsumableArray(prev), [destroyAction]);\n            });\n          }\n        },\n        update: function update(newConfig) {\n          function updateAction() {\n            var _a;\n            (_a = modalRef.current) === null || _a === void 0 ? void 0 : _a.update(newConfig);\n          }\n          if (modalRef.current) {\n            updateAction();\n          } else {\n            setActionQueue(function (prev) {\n              return [].concat(_toConsumableArray(prev), [updateAction]);\n            });\n          }\n        }\n      };\n    };\n  }, []);\n  var fns = React.useMemo(function () {\n    return {\n      info: getConfirmFunc(withInfo),\n      success: getConfirmFunc(withSuccess),\n      error: getConfirmFunc(withError),\n      warning: getConfirmFunc(withWarn),\n      confirm: getConfirmFunc(withConfirm)\n    };\n  }, []);\n  return [fns, /*#__PURE__*/React.createElement(ElementsHolder, {\n    key: \"modal-holder\",\n    ref: holderRef\n  })];\n}\nexport default useModal;","map":{"version":3,"names":["_toConsumableArray","React","usePatchElement","withConfirm","withError","withInfo","withSuccess","withWarn","HookModal","uuid","ElementsHolder","memo","forwardRef","_props","ref","elements","patchElement","useImperativeHandle","createElement","Fragment","useModal","holderRef","useRef","useState","actionQueue","setActionQueue","useEffect","length","cloneQueue","forEach","action","getConfirmFunc","useCallback","withFunc","hookConfirm","config","_a","modalRef","createRef","closeFunc","modal","key","afterClose","current","destroy","destroyAction","prev","concat","update","newConfig","updateAction","fns","useMemo","info","success","error","warning","confirm"],"sources":["/Users/poppie/Desktop/development/messenger/app/frontend/node_modules/antd/es/modal/useModal/index.js"],"sourcesContent":["import _toConsumableArray from \"@babel/runtime/helpers/esm/toConsumableArray\";\nimport * as React from 'react';\nimport usePatchElement from '../../_util/hooks/usePatchElement';\nimport { withConfirm, withError, withInfo, withSuccess, withWarn } from '../confirm';\nimport HookModal from './HookModal';\nlet uuid = 0;\nconst ElementsHolder = /*#__PURE__*/React.memo( /*#__PURE__*/React.forwardRef((_props, ref) => {\n  const [elements, patchElement] = usePatchElement();\n  React.useImperativeHandle(ref, () => ({\n    patchElement\n  }), []);\n  // eslint-disable-next-line react/jsx-no-useless-fragment\n  return /*#__PURE__*/React.createElement(React.Fragment, null, elements);\n}));\nfunction useModal() {\n  const holderRef = React.useRef(null);\n  // ========================== Effect ==========================\n  const [actionQueue, setActionQueue] = React.useState([]);\n  React.useEffect(() => {\n    if (actionQueue.length) {\n      const cloneQueue = _toConsumableArray(actionQueue);\n      cloneQueue.forEach(action => {\n        action();\n      });\n      setActionQueue([]);\n    }\n  }, [actionQueue]);\n  // =========================== Hook ===========================\n  const getConfirmFunc = React.useCallback(withFunc => function hookConfirm(config) {\n    var _a;\n    uuid += 1;\n    const modalRef = /*#__PURE__*/React.createRef();\n    let closeFunc;\n    const modal = /*#__PURE__*/React.createElement(HookModal, {\n      key: `modal-${uuid}`,\n      config: withFunc(config),\n      ref: modalRef,\n      afterClose: () => {\n        closeFunc === null || closeFunc === void 0 ? void 0 : closeFunc();\n      }\n    });\n    closeFunc = (_a = holderRef.current) === null || _a === void 0 ? void 0 : _a.patchElement(modal);\n    return {\n      destroy: () => {\n        function destroyAction() {\n          var _a;\n          (_a = modalRef.current) === null || _a === void 0 ? void 0 : _a.destroy();\n        }\n        if (modalRef.current) {\n          destroyAction();\n        } else {\n          setActionQueue(prev => [].concat(_toConsumableArray(prev), [destroyAction]));\n        }\n      },\n      update: newConfig => {\n        function updateAction() {\n          var _a;\n          (_a = modalRef.current) === null || _a === void 0 ? void 0 : _a.update(newConfig);\n        }\n        if (modalRef.current) {\n          updateAction();\n        } else {\n          setActionQueue(prev => [].concat(_toConsumableArray(prev), [updateAction]));\n        }\n      }\n    };\n  }, []);\n  const fns = React.useMemo(() => ({\n    info: getConfirmFunc(withInfo),\n    success: getConfirmFunc(withSuccess),\n    error: getConfirmFunc(withError),\n    warning: getConfirmFunc(withWarn),\n    confirm: getConfirmFunc(withConfirm)\n  }), []);\n  return [fns, /*#__PURE__*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